package com.blq.web.ServeClassify.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.blq.common.annotation.RepeatSubmit;
import com.blq.common.annotation.Log;
import com.blq.common.core.controller.BaseController;
import com.blq.common.core.domain.PageQuery;
import com.blq.common.core.domain.R;
import com.blq.common.core.validate.AddGroup;
import com.blq.common.core.validate.EditGroup;
import com.blq.common.enums.BusinessType;
import com.blq.common.utils.poi.ExcelUtil;
import com.blq.web.ServeClassify.domain.vo.ServeClassifyVo;
import com.blq.web.ServeClassify.domain.bo.ServeClassifyBo;
import com.blq.web.ServeClassify.service.IServeClassifyService;
import com.blq.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 服务类别Controller
 *
 * @author Blq
 * @date 2022-11-07
 */
@Validated
@Api(value = "服务类别控制器", tags = {"服务类别管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/web/ServeClassify")
public class ServeClassifyController extends BaseController {

    private final IServeClassifyService iServeClassifyService;

    /**
     * 查询服务类别列表
     */
    @ApiOperation("查询服务类别列表")
    @SaCheckPermission("web:ServeClassify:list")
    @GetMapping("/list")
    public TableDataInfo<ServeClassifyVo> list(ServeClassifyBo bo, PageQuery pageQuery) {
        return iServeClassifyService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务类别列表
     */
    @ApiOperation("导出服务类别列表")
    @SaCheckPermission("web:ServeClassify:export")
    @Log(title = "服务类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ServeClassifyBo bo, HttpServletResponse response) {
        List<ServeClassifyVo> list = iServeClassifyService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务类别", ServeClassifyVo.class, response);
    }

    /**
     * 获取服务类别详细信息
     */
    @ApiOperation("获取服务类别详细信息")
    @SaCheckPermission("web:ServeClassify:query")
    @GetMapping("/{id}")
    public R<ServeClassifyVo> getInfo(@ApiParam("主键")
                                      @NotNull(message = "主键不能为空")
                                      @PathVariable("id") Long id) {
        return R.ok(iServeClassifyService.queryById(id));
    }

    /**
     * 新增服务类别
     */
    @ApiOperation("新增服务类别")
    @SaCheckPermission("web:ServeClassify:add")
    @Log(title = "服务类别", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ServeClassifyBo bo) {
        return toAjax(iServeClassifyService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改服务类别
     */
    @ApiOperation("修改服务类别")
    @SaCheckPermission("web:ServeClassify:edit")
    @Log(title = "服务类别", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ServeClassifyBo bo) {
        return toAjax(iServeClassifyService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除服务类别
     */
    @ApiOperation("删除服务类别")
    @SaCheckPermission("web:ServeClassify:remove")
    @Log(title = "服务类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                          @NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iServeClassifyService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
